/**
 * 初始化 echarts(pie) 的封装
 *
 * 约定：
 *
 * @author fhw
 */
(function () {
    var PieEchart = function (echartId, url,name) {
    	debugger;
        this.echartId = echartId;
        this.url = url;
        this.queryParams = {}; // 向后台传递的自定义参数
        this.option={};
        this.name=name;
    };

    PieEchart.prototype = {
        /**
         * 初始化echart
         */
        init: function () {
            this.option= {
            		title: {
            	        text: this.name,
            	        left: 'center'
            	    },
            	    tooltip: {
            	    	trigger: 'item',
            	        formatter: "{a} <br/>{b} : {c} ({d}%)"
            	    },
            	    toolbox: {
            	        show: false
            	    },
            	    legend: {
            	    	type: 'scroll',
            	        orient: 'vertical',
            	        right: 10,
            	        top: 20,
            	        bottom: 20,
            	        
            	    },
            	    series: [
            	        {
            	            name:'',
            	            type:'pie',
            	            radius : '55%',
            	            center: ['50%', '50%'],
            	            
            	        }
            	    ]
            	};
            var curechartId=this.echartId;
        	var curoption=this.option;
            $.ajax({
		    	type: "POST",
				url: this.url,
				async:false,
				data:this.queryParams,
				dataType: "json",
				success: function(data){
					debugger;
					curoption.series[0].data=[];
					curoption.legend.data=[];
					for(var i=0;i<data.length;i++){
						curoption.legend.data.push(data[i].data);
						curoption.series[0].data.push({name:data[i].data,value:data[i].num});
	    	        };
	    	        var myChart = echarts.init(document.getElementById(curechartId));
	    	  	    myChart.clear();
	    	  	    myChart.setOption(curoption, true); 
				}
				
			});
            return this;
        }
    };
    window.PieEchart = PieEchart;
}());
